import ij.*;
import ij.io.*;
import ij.process.*;
import ij.plugin.filter.GaussianBlur;


public class DImageProcessor {

	//get
	//put
	//filter
		//blur
		//sharpen
		//glow
	//resize
	
	public static String resizeImg(String fileAbsolutePath, int rWidth, int rHeight) {
        try {
            Opener opener = new Opener();
            ImagePlus imp = opener.openImage(fileAbsolutePath);
            ImageProcessor ip = imp.getProcessor();

            //resize image
            ImageProcessor resizedProcessor = ip.resize(rWidth, rHeight, true);
            imp.setProcessor(resizedProcessor);
            
            String saveAsFilePath = "Storage/resized-" +  fileAbsolutePath.substring(fileAbsolutePath.indexOf('/') + 1);;
            IJ.save(imp, saveAsFilePath);
            return saveAsFilePath;
        } catch (Exception e) {
            //logger.error("Error while resizing Image.");
            e.printStackTrace();
            return null;
        }
	}
	
	public static String sharpenImg(String file) {
		try {
            Opener opener = new Opener();
            ImagePlus imp = opener.openImage(file);
            ImageProcessor ip = imp.getProcessor();

            //sharpen image
            ip.sharpen();
            
            String saveAsFilePath = "Storage/sharpen-" + file.substring(file.indexOf('/') + 1);
            IJ.save(imp, saveAsFilePath);
            return saveAsFilePath;
        } catch (Exception e) {
            //logger.error("Error while resizing Image.");
            e.printStackTrace();
            return null;
        }
	}
	
	public static String blurImg(String file) {
		try {
            Opener opener = new Opener();
            ImagePlus imp = opener.openImage(file);
            ImageProcessor ip = imp.getProcessor();
            
            //blur image
            GaussianBlur blur = new GaussianBlur();
            blur.blurGaussian(ip, 10, 10, 0.02);

            String saveAsFilePath = "Storage/blur-" + file.substring(file.indexOf('/') + 1);
            IJ.save(imp, saveAsFilePath);
            return saveAsFilePath;
        } catch (Exception e) {
            //logger.error("Error while resizing Image.");
            e.printStackTrace();
            return null;
        }
	}
	
	public static String flipImg(String file) {
		try {
            Opener opener = new Opener();
            ImagePlus imp = opener.openImage(file);
            ImageProcessor ip = imp.getProcessor();
            
            //flip image
            ip.flipHorizontal();

            String saveAsFilePath = "Storage/flip-" +  file.substring(file.indexOf('/') + 1);
            IJ.save(imp, saveAsFilePath);
            return saveAsFilePath;
        } catch (Exception e) {
            //logger.error("Error while resizing Image.");
            e.printStackTrace();
            return null;
        }
	}
	
	
	
}
